<template>
    <div>
        <div @click="popup.openPopup" class="vue-flow-model">
            <n-icon size="30" color="#18A058">
                <ArrowAnnotation/>
            </n-icon>
            <Handle id="Score-inlet" type="target" :position="Position.Left"
                    :is-valid-connection="props.isValidSourcePos"/>
        </div>
        <span>答案评分</span>
        <flow-popup-window
            :show="popup.show"
            :on-click-outside="popup.clickPopupOutside"
            :x="popup.x"
            :y="popup.y"
        >
            <n-card title="答案评分">
              <p>传说 : 只有被该节点所连接的组件才会计算分数</p>
                <template #footer>
                    <n-space>
                        <n-button>获取上级节点数据</n-button>
<!--                        <n-button @click="score">评分</n-button>-->
                    </n-space>
                </template>
            </n-card>
        </flow-popup-window>
    </div>
</template>

<script setup>

import {Handle, Position} from "@vue-flow/core";
import {ArrowAnnotation} from "@vicons/carbon";
import {useElementsStore} from "@/stores/elements";
import workApi from "@/http/workApi";
import FlowPopupWindow from "@/components/VueFlowModel/vueFlowPopupWindow/FlowPopupWindow.vue";

const props = defineProps(['isValidTargetPos', 'isValidSourcePos', 'id', 'data'])
const elements = useElementsStore()
// 点击弹窗
const popup = reactive({
    show: false,
    x: null,
    y: null,
    wait: false,
    clickPopupOutside: () => {
        popup.closedPopup()
    },
    openPopup: (e) => {
        popup.x = e.x
        popup.y = e.y
        popup.show = true
    },
    closedPopup: () => {
        if (!popup.wait) {
            console.log(22)
            popup.show = false;
        }
    },
    reopen: () => {
        popup.show = true
    }
})

const score = ()=>{
    workApi.post("perform_tasks/arima",{
        data:props.data.data,
        column:field.value,
        forecast_steps:forecast_steps.value,
        units:"期"
    }).then(r=>{
        props.data.data = r.data
    })
}

const getSuperiorData = () => {
    // 获取上级节点数据
    for (let i of elements.elements) {
        if (i['target'] === props.id) {
            for (let j of elements.elements) {
                if (j.id === i['source']) {
                    props.data.data = {...j.data.data};
                    props.data.data.title.map(s => {
                        // 移除可修改
                        delete s.render
                        return s
                    })
                    return
                }
            }
        }
    }
}
</script>

<style scoped lang="less">
.n-card {
    p {
        margin-top: 20px;
    }
}
</style>